<?php
/**
 * 信誉日志
 * @author Ice iceinto@mallog.com.cn
 */
class CreditLogModel extends BaseModel
{
	/**
	 * 执行单一日志添加
	 * @param int $uid 用户
	 * @param int $tid 类型
	 * @param int $rid 规则
	 * @param int $num 数值
	 * @param int $operator 操作符
	 * @author Ice <iceinto@mallog.com.cn>
	 */
    public function addOne($uid, $tid, $rid, $num, $operator = 1){
    	
    }
    
    /**
     * 根据条件获取数量
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function findCount($map){
    	return $this->where($map)->count();
    }
    
    /**
     * 查询当前所有条件下所有数量
	 * @param int $uid 用户
	 * @param int $tid 类型
	 * @param int $rid 规则
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function findAllCount($uid, $tid, $rid){
    	$map = array();
    	$map['uid'] = $uid;
    	$map['tid'] = $tid;
    	$map['rid'] = $rid;
    	return $this->findCount($map);
    }
    
    /**
     * 获取当天用户对应类型规则记录说
	 * @param int $uid 用户
	 * @param int $tid 类型
	 * @param int $rid 规则
	 * @author Ice <iceinto@mallog.com.cn>
     */
    public function findDayCount($uid, $tid, $rid){
    	$map = array();
    	//处理时间
    	import("@.ORG.Util.Date");
    	$date = new Date();
    	$startTime = $date->format('%Y-%m-%d');
    	$date = $date->dateAdd(1, 'd');
    	$endTime = $date->format('%Y-%m-%d');
    	$startTime = strtotime($startTime);//今天开始时间
    	$endTime = strtotime($endTime);//明天开始时间
    	//拼接搜索条件
    	$map['uid'] = $uid;
    	$map['tid'] = $tid;
    	$map['rid'] = $rid;
    	$map['create_time'] = array(array('egt', $startTime),array('lt', $endTime)) ;
    	return $this->findCount($map);   	
    }
    
    /**
     * 获取用户日志记录
     * @param int $uid 用户
     * @param int $tid 类型
     * @return array
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getUserLogs($uid, $tid){
    	$map = array();
    	$map['tid'] = $tid;
    	$map['uid'] = $uid;
    	$logs = $this->where($map)->limit('0,20')->order('create_time DESC')->select();
    	//组织显示
    	$types = D('CreditType')->getAll();
    	$rules = D('CreditRule')->getAll();
    	foreach ($logs as $key=>$log){
    		$logs[$key]['type'] = $types[$log['tid']];
    		$logs[$key]['rule'] = $rules[$log['rid']];
    	}
    	return $logs;
    }
}
?>